package com.wquick.base.utils.device

import android.os.Build

enum class RomType {
    Xiaomi,
    Meizu,
    Huawei,
    Honor,
    Oppo,
    Vivo,
    Samsung,
    NotCare
}

val romModel by lazy { Build.MODEL }
val romBrand by lazy { Build.BRAND }
val romManufacturer by lazy { Build.MANUFACTURER }

private val romTypeCacheRunner by lazy {
    CacheRunner<Unit, RomType> {
        val manufacturer = romManufacturer.lowercase()
        val brand = romBrand.lowercase()
        if (isRom(brand, manufacturer, "xiaomi")) {
            RomType.Xiaomi
        } else if (isRom(brand, manufacturer, "samsung")) {
            RomType.Samsung
        } else if (isRom(brand, manufacturer, "vivo")) {
            RomType.Vivo
        } else if (isRom(brand, manufacturer, "oppo")) {
            RomType.Oppo
        } else if (isRom(brand, manufacturer, "huawei")) {
            RomType.Huawei
        } else if (isRom(brand, manufacturer, "honor")) {
            RomType.Honor
        } else if (isRom(brand, manufacturer, "meizu")) {
            RomType.Meizu
        } else {
            RomType.NotCare
        }
    }
}

private fun isRom(brand: String, manufacturer: String, name: String): Boolean {
    return brand.contains(name) || manufacturer.contains(name)
}

fun getRomType() = romTypeCacheRunner.get(Unit) ?: RomType.NotCare
fun isXiaomi() = getRomType() == RomType.Xiaomi
fun isHuawei() = getRomType() == RomType.Huawei
fun isHonor() = getRomType() == RomType.Honor
fun isOppo() = getRomType() == RomType.Oppo
fun isVivo() = getRomType() == RomType.Vivo
fun isMeizu() = getRomType() == RomType.Meizu
fun isSamsung() = getRomType() == RomType.Samsung
